package cn.shengchao.examstar.ai.domain.event;

import cn.shengchao.examstar.ai.domain.model.studyplan.StudyPlanId;
import cn.shengchao.examstar.ai.domain.valueobject.SpecificationType;
import cn.shengchao.examstar.ai.domain.valueobject.UserId;
import cn.shengchao.examstar.shared.domain.event.DomainEvent;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 学习计划创建事件
 * 当学习计划被成功创建时发布此事件
 */
@Getter
public class StudyPlanCreatedEvent extends DomainEvent {
    
    private final StudyPlanId studyPlanId;
    private final UserId userId;
    private final SpecificationType specificationType;
    private final LocalDateTime occurredOn;
    
    public StudyPlanCreatedEvent(StudyPlanId studyPlanId, 
                                UserId userId, 
                                SpecificationType specificationType) {
        this.studyPlanId = Objects.requireNonNull(studyPlanId, "学习计划ID不能为空");
        this.userId = Objects.requireNonNull(userId, "用户ID不能为空");
        this.specificationType = Objects.requireNonNull(specificationType, "类目不能为空");
        this.occurredOn = LocalDateTime.now();
    }
    
    public LocalDateTime occurredOn() {
        return occurredOn;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StudyPlanCreatedEvent that = (StudyPlanCreatedEvent) o;
        return Objects.equals(studyPlanId, that.studyPlanId) &&
                Objects.equals(userId, that.userId) &&
                Objects.equals(specificationType, that.specificationType) &&
                Objects.equals(occurredOn, that.occurredOn);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(studyPlanId, userId, specificationType, occurredOn);
    }
    
    @Override
    public String toString() {
        return "StudyPlanCreatedEvent{" +
                "studyPlanId=" + studyPlanId +
                ", userId=" + userId +
                ", specificationType=" + specificationType +
                ", occurredOn=" + occurredOn +
                '}';
    }
}